﻿using System.Data.Entity;
using System.Linq;
using Zeus.Biz.MySql.EF.Model;

namespace Zeus.Biz.MySql.EF.Config
{
    public class ZeusMyContext : DbContext
    {
        public ZeusMyContext(string connectionString)
            : base(connectionString)
        {

        }

        public DbSet<Customer> Customers { get; set; }
        public DbSet<Order> Orders { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Customer>()
                .HasMany(d => d.Orders)
                .WithOptional(l => l.Customer)
                .WillCascadeOnDelete(true);

            // Entity Type Configuration
            modelBuilder.Configurations.Add(new CustomerConfiguration());
            modelBuilder.Configurations.Add(new OrderConfiguration());
        }
    }
}
